/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 *
 * http://extjs.com/license
 */
var IPAddress = "";
Ext.onReady(function(){
    var Datos = "";
    // NOTE: This is an example showing simple state management. During development,
    // it is generally best to disable state management as dynamically-generated ids
    // can change across page loads, leading to unpredictable results.  The developer
    // should ensure that stable state ids are set for stateful components in real apps.
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

    var body = Ext.getBody();
    var mask = new Ext.LoadMask(body);
    mask.show();
    Ext.Ajax.request({

        url: 'http://localhost:8080/presto/edge/api',
        method:"POST",
        timeout:60000,
        params:{
            "inputStream": "{'version': '1.1','sid': 'CountryDetailsREST','svcVersion':'0.1','oid': 'invoke','params': ['"+IPAddress+"']}"
        },
        success: function(response){
            mask.hide();
            Datos = Ext.util.JSON.decode(Ext.util.JSON.decode(response.responseText).response).Datos;
            console.log(Datos);

            var viewport = new Ext.Viewport({
                layout:'border',
                items:[{
                    region:'west',
                    id:'west-panel',
                    title:'West',
                    split:true,
                    width: 200,
                    minSize: 175,
                    maxSize: 400,
                    collapsible: true,
                    margins:'35 0 5 5',
                    cmargins:'35 5 5 5',
                    layout:'accordion',
                    layoutConfig:{
                        animate:true
                    },
                    items: [{
                        html: 'Items',
                        title:'Navigation',
                        autoScroll:true,
                        border:false,
                        iconCls:'nav'
                    }]
                },{
                    xtype:'portal',
                    region:'center',
                    margins:'35 5 5 0',
                    items:[{
                        columnWidth:.33,
                        style:'padding:10px 0 10px 10px',
                        items:[{
                            title: 'Local Currency against Dollar (USD)',
                            tools: tools,
                            html: 'Your IP is: <B>' +Datos.IP+ '</B>' +
                            'therefore the data indicates that you are in <B>'
                            +Datos.Country+ '</B>. Your local currency is' +
                            '<B>' +Datos.Currency+ '</B>. So with ' +
                            '<B>' +Datos.XchangeRate+ ' ' +Datos.Currency+
                            '</B> you get <B>1 USD</B>'

                        },{
                            title: 'Google Graph',
                            tools: tools,
                            html: 'ytghoiasjndfpoianswpfiouawpieufbiwuebf'
                        }]
                    },{
                        columnWidth:.33,
                        style:'padding:10px 0 10px 10px',
                        items:[{
                            title: 'Google Map',
                            tools: tools,
                            height:340,
                            layout:'fit',
                            items:[{
                                columnWidth:.33,
                                style:'padding:10px 0 10px 10px',
                                items:[{
                                    xtype: 'gmappanel',
                                    zoomLevel: 14,
                                    gmapType: 'map',
                                    mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'],
                                    mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],
                                    setCenter: {
                                        geoCodeAddr: '4 Yawkey Way, Boston, MA, 02215-3409, USA',
                                        marker: {
                                            title: 'Fenway Park'
                                        }
                                    },
                                    markers: [{
                                        lat: 42.339641,
                                        lng: -71.094224,
                                        marker: {
                                            title: 'Boston Museum of Fine Arts'
                                        },
                                        listeners: {
                                            click: function(e){
                                                Ext.Msg.alert('Its fine', 'and its art.');
                                            }
                                        }
                                    }]
                                }]
                            }]
                        }]
                    },{
                        columnWidth:.33,
                        style:'padding:10px',
                        items:[{
                            title: 'Reuters',
                            tools: tools,
                            html: 'ytghoiasjndfpoianswpfiouawpieufbiwuebf'
                        },{
                            title: 'Yahoo Finance',
                            tools: tools,
                            html: 'ytghoiasjndfpoianswpfiouawpieufbiwuebf'
                        }]
                    }]
                }]
            });


        }

    });


    // create some portlet tools using built in Ext tool ids
    var tools = [{
        id:'gear',
        handler: function(){
            Ext.Msg.alert('Message', 'The Settings tool was clicked.');
        }
    },{
        id:'close',
        handler: function(e, target, panel){
            panel.ownerCt.remove(panel, true);
        }
    }];


});
